<template>
  <Dialog
    :visible="addVisible"
    title="审核"
    :top="'25vh'"
    :width="480"
    @close="addVisible = false"
  >
    <div style="padding: 5px" v-if="addVisible">
      <el-form :model="formData" label-width="90px" ref="ruleFormRef"  :labelPosition="'left'">
        <el-form-item label="审核结果：" prop="auditStatus">
          <!-- <el-select v-model="formData.auditStatus" placeholder="请选择" style="width: 100%">
            <el-option :value="item.value"   :label="item.text" :key="item.value" v-for="item in diagnosisFlagEnum"></el-option>
          </el-select> -->
          <el-radio-group
            v-model="formData.auditStatus"
          >
            <el-radio
              :label="item.value"
              :key="item.value"
              v-for="item in diagnosisFlagEnums"
              >{{ item.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核意见：" prop="refuseReason">
          <el-input v-model="formData.refuseReason" placeholder="请输入" style="border: 1px solid #f5f7fa;" type="textarea" />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <el-button @click="handleSubmit" type="primary">确 定</el-button>
      <el-button @click="addVisible = false">取 消</el-button>
    </template>

  </Dialog>
</template>

<script setup lang="ts">
import type { AuditExam } from '@/types/exam';
import { auditExam } from '@/api/exam';
const addVisible = ref(false);
import type { FormRules, ElTree } from 'element-plus';
import stores from '@/store';
const ruleFormRef = ref();
// const diagnosisFlagEnum = ref<any>(
//   stores.useBaseDataStore().getEnumSelect('examAuditStatusEnum')
// );
const diagnosisFlagEnums = ref<any>(
 [
  { label: '同意', value: '3'},
  { label: '驳回', value: '4'},
 ]
);


let rules = reactive<FormRules<any>>({
});
const formData = ref<AuditExam>({
  execId: '',
  auditStatus: '3',
  refuseReason: '',
});
defineExpose<{
  open: (menu: number) => void;
}>({
  open: (menu: number) => {
    formData.value.execId = menu;
    formData.value.auditStatus = '3'
    formData.value.refuseReason = ''
    addVisible.value = true;
  },
});

const handleSubmit = async () => {

  let res = await auditExam(formData.value);
  if (res.code == '200') {
    ElMessage({
      type: 'success',
      message: res.msg,
      duration: 2000,
    });
    closeDrawer();
  } else {

  }
  // const form = ruleFormRef.value;

  // await form.validate(async(valid: any, fields: any) => {
  //   if (valid) {
      
  //   } else {
  //     //console.log('error submit!', fields);
  //   }
  // });
  
};
const emit = defineEmits(['closeDrawer']);
const closeDrawer = () => {
  addVisible.value = false;
  emit('closeDrawer');
};
</script>
<style lang="scss" scoped>
h1{
    font-family: Microsoft YaHei, Microsoft YaHei;
    font-weight: 400;
    font-size: var(--el-form-label-font-size);
    color: var(--el-text-color-regular);
    margin-bottom: 20px;
    text-align: left;
    font-style: normal;
    text-transform: none;
}</style>
